#ifndef EM80_DAC_CONFIG_HPP
#define EM80_DAC_CONFIG_HPP

#include "../packet_base.hpp"
#include "../payload_headers.hpp"
#include "../../v8stdint.h"


#include <memory>

namespace em80_driver
{

class DACConfig : public EM80PayloadBase
{
public:
    DACConfig(EM80PacketPtr &packet) : EM80PayloadBase(packet, "DACConfig", false, 3) {}

    struct Data
    {
        Data() : dac(0), value(0) {}
        uint8_t dac;
        uint16_t value;
    }__attribute__((packed));

    struct Control
    {
        enum State
        {
            OFF = 0,
            ON
        };
    };

    Data data;

    ~DACConfig() {}

    //not to be used directly by external source
    bool serialize()
    {
        //TODO : is it directly control the raw data
        std::shared_ptr<Buffer> byteStream = std::make_shared<Buffer>(0);
        buildBytes(static_cast<uint8_t>(Header::DACConfig), *byteStream);
        buildBytes(static_cast<uint8_t>(length), *byteStream);
        buildBytes(data.dac, *byteStream);
        buildBytes(data.value, *byteStream);
    
        int i = 0;

        for(auto iter = packet->payload(); iter != packet->payload() + length + 2; iter++, i++)
        {
            *iter = (*byteStream)[i];
        }

        return true;
    }

    bool deserialize()
    {
        std::vector<uint8_t> byteStream;

        byteStream.assign(packet->payload(), packet->payload() + static_cast<uint32_t>(length) + 2);


        //TODO: check them

        return true;
    }
};

} // namespace em80_driver

#endif /* EM80_ADC_CONFIG_HPP*/
